﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Framework;
using NUnit.Framework;
using QuickTest.Core.Compilation;
using Rhino.Mocks;

namespace QuickTest.Tests.Core.Compilation
{
    [TestFixture]
    public class CompilerLoggerTests
    {
        private ICompilerEvents compilerEvents;
        private ILogger logger;
        private IEventSource eventSource;

        [SetUp]
        public void SetUp()
        {
            compilerEvents = MockRepository.GenerateStub<ICompilerEvents>();
            logger = new CompilerLogger(compilerEvents);
            eventSource = MockRepository.GenerateStub<IEventSource>();
        }

        [Test]
        public void should_log_build_events()
        {
            logger.Initialize(eventSource);
            eventSource.Raise(e => e.BuildStarted += null, this, new BuildStartedEventArgs(string.Empty, string.Empty));

            compilerEvents.AssertWasCalled(e => e.RaiseCompileStarted(Arg<CompileStartedEventArgs>.Is.Anything));
        }

        [Test]
        public void should_log_build_finished()
        {
            logger.Initialize(eventSource);
            eventSource.Raise(e => e.BuildFinished += null, this, new BuildFinishedEventArgs(string.Empty, string.Empty, true));

            compilerEvents.AssertWasCalled(e => e.RaiseCompileFinished(Arg<CompileFinishedEventArgs>.Is.Anything));
        }

        [Test]
        public void should_log_error_raised()
        {
            logger.Initialize(eventSource);
            eventSource.Raise(e => e.ErrorRaised += null, this, new BuildErrorEventArgs(string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, string.Empty, string.Empty, string.Empty));

            compilerEvents.AssertWasCalled(e => e.RaiseCompileError(Arg<CompileErrorEventArgs>.Is.Anything));
        }
    }
}
